/**
 * 
 */
package com.Data;


import android.app.AlertDialog;
import android.content.Context;
import android.os.AsyncTask;
import com.SoapClasses.SoapNotifications;
import com.shareup.R;
import com.utils.AlertDialogHelper;


/**
 * @author Chris
 * 
 */
public class Notifications extends AsyncTask<Integer, String, Notifications[]> {

    public static final int ACTION_DELETE = 113;

    public static final int ACTION_GET = 110;

    public static final int ACTION_GET_COUNT = 0;

    private String ExtraData;

    public String getExtraData() {

        return this.ExtraData;
    }

    public void setExtraData(String extraData) {

        this.ExtraData = extraData;
    }

    private onDeleteNotification callbackDelete;

    private onGetNotificationsCompleted callbackGet;

    private onGetNotificationsCountCompleted callbackGetCount;

    private Context context;

    private String Count;

    private String Date;

    private String Extra;

    private User From;

    private int idNotification;

    private int mode;

    private AlertDialog progress;

    private User To;

    private int Type;

    public interface onDeleteNotification {

        void Completed(String res);
    }

    public interface onGetNotificationsCompleted {

        void Completed(Notifications[] result);
    }

    public interface onGetNotificationsCountCompleted {

        void Completed(String result);
    }

    public Notifications(Context context, int ACTION) {

        super();
        this.context = context;
        this.mode = ACTION;
    }

    public Notifications(int ACTION) {

        this.mode = ACTION;
    }

    public String getCount() {

        return Count;
    }

    public String getDate() {

        return this.Date;
    }

    public String getExtra() {

        return Extra;
    }

    public User getFrom() {

        return this.From;
    }

    public int getIdNotification() {

        return this.idNotification;
    }

    public User getTo() {

        return this.To;
    }

    public int getType() {

        return this.Type;
    }

    public void setCallbackDelete(onDeleteNotification callbackDelete) {

        this.callbackDelete = callbackDelete;
    }

    public void setCallbackGet(onGetNotificationsCompleted callbackGet) {

        this.callbackGet = callbackGet;
    }

    public void setCallbackGetCount(onGetNotificationsCountCompleted callbackGetCount) {

        this.callbackGetCount = callbackGetCount;
    }

    public void setCount(String count) {

        this.Count = count;
    }

    public void setDate(String date) {

        this.Date = date;
    }

    public void setExtra(String extra) {

        this.Extra = extra;
    }

    public void setFrom(User from) {

        this.From = from;
    }

    public void setIdNotification(int idNotification) {

        this.idNotification = idNotification;
    }

    public void setTo(User to) {

        this.To = to;
    }

    public void setType(int type) {

        this.Type = type;
    }

    /*
     * (non-Javadoc)
     * @see android.os.AsyncTask#doInBackground(java.lang.Object[])
     */
    @Override
    protected Notifications[] doInBackground(Integer... par) {

        SoapNotifications sn = new SoapNotifications();
        Notifications[] n = new Notifications[1];
        Notifications no = new Notifications(0);
        switch (mode) {

            case ACTION_GET:
                return sn.getNotifications();
            case ACTION_GET_COUNT:
                no.setCount(sn.getNotificationsCount());
                n[0] = no;
                return n;
            case ACTION_DELETE:
                no.setExtra(sn.deleteNotifications(this.idNotification));
                n[0] = no;
                return n;
        }
        return null;
    }

    @Override
    protected void onPostExecute(Notifications[] result) {

        if (callbackGet != null) {
            progress.dismiss();
            callbackGet.Completed(result);
        }
        if (callbackGetCount != null)
            callbackGetCount.Completed(result[0].getCount());

        if (callbackDelete != null)
            callbackDelete.Completed(result[0].getExtra());

    }

    @Override
    protected void onPreExecute() {

        if (mode == ACTION_GET) {
            String message = context.getString(R.string.dialog_wait);
            progress = AlertDialogHelper.setProgressDialog(progress, message, context);
            // progress.show();
        }

    }
}
